home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Tools&Utilities / MathPad 2.4 / Examples / pulse amp < prev    next >
Text File  |  1996-04-02  |  2KB  |  42 lines

  1. -- Calculate an amplifier output pulse shape.
  2. -- Requires XFun "fft".
  3.  
  4. decay = 1u     -- input exponential pulse decay time
  5. bw1 = 200K     -- bandwidth of 1st amplifier stage
  6. bw2 = 150K     -- bandwidth of 2nd amplifier stage
  7.  
  8. tmax = 8u      -- time scale
  9. nsamp = 64     -- number of samples to use in transform
  10.  
  11. y(t) = exp(-t/decay) -- input pulse
  12.  
  13. Xmin=0; Xmax=tmax/1u; t = X*1u; Xlabel="µsec"
  14. plotline y(t)
  15.  
  16. newaxis
  17. dt=tmax/(nsamp-1)
  18. ys[i]={y((i-1)*dt),0} -- sample the input to get a complex time series
  19. fft(ys[:nsamp]):;     -- transform the input signal to freq domain
  20. fmax=.5/dt;  fmax:3.94e6; -- highest freq used in model
  21.  
  22. H(f,bw) = Cdiv({1,0},{1,f/bw}) -- freq response of a single RC lowpass
  23. freq(i) = (i-1)*fmax/(nsamp/2+1)  
  24. amp(bw)[i] = H(freq(i),bw)  -- resp at discrete freqs of the transform
  25.  
  26. stage1:=convolve(transform,  -- convolve transform of input pulse
  27.                  amp(bw1)):; -- with 1st amplifier response
  28. invfft(stage1):;             -- invert to get time series
  29. plotline realpart(transform) -- show 1st stage output pulse shape
  30.  
  31. invfft(convolve(stage1,      -- convolve 1st stage output freqs
  32.                 amp(bw2))):; -- with 2nd amplifier response
  33. plotline realpart(transform) -- show 2nd stage output pulse shape
  34.  
  35.  
  36. ------------ utility routines for complex numbers ----------------
  37. Cmult(A,B) = {A[1]*B[1]-A[2]*B[2],A[2]*B[1]+A[1]*B[2]}
  38. Cdiv(A,B)={(B[1]*A[1]+B[2]*A[2])/(B[1]^2+B[2]^2),
  39.          (B[1]*A[2]-B[2]*A[1])/(B[1]^2+B[2]^2)}
  40. convolve(A,B)[i,j] = Cmult(A[i],B[i])[j] dim[count(A),2]
  41. realpart(A)[i] = A[i,1] dim[count(A)]
  42.